﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.Supervise.Model.Enum;
using System.Data;
using HZ.Supervise.Model.Query;

namespace HZ.Supervise.Web.Hospital
{
    public partial class ContractOrders : BasePage
    {
        HZ.Supervise.IBLL.IExecuteContext i = HZ.Supervise.BLLFactory.ExecuteContext();

        public ContractOrders()
        {
            this.ModuleNo = Module.大型设备监管.ToString();
            this.PageOperateType = OperateType.合同查看.ToString();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ddlArea.InitAreaID = CurrentAccount.GetUser().Org.Area.AreaID;
                //SetBind();
            }
        }

        /// <summary>
        /// 根据查询条件，绑定相应的信息
        /// </summary>
        private void SetBind()
        {
            int totalCount = 0;
            DataTable dt = i.GetOrderDXSB(GetQurey(), this.AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalCount);
            AspNetPager1.RecordCount = totalCount;
            gvwOrder.PageSize = AspNetPager1.PageSize;
            gvwOrder.DataSource = dt;
            gvwOrder.DataBind();
        }
        private QOrderDXSB GetQurey()
        {
            QOrderDXSB od = new QOrderDXSB();
            od.OrderStatus = 1;
            od.HospitalName = txtHospitalName.Text.Trim();
            od.OrderName = txtOrderName.Text.Trim();
            od.AreaID = ddlArea.SelectedAreaID;
            if (!string.IsNullOrEmpty(txtTimeFrom.Text.Trim()) && string.IsNullOrEmpty(txtTimeTo.Text.Trim()))
            {
                od.Append += string.Format("StartTime >= '{0}'", txtTimeFrom.Text.Trim());
            }
            else if (!string.IsNullOrEmpty(txtTimeFrom.Text.Trim()) && !string.IsNullOrEmpty(txtTimeTo.Text.Trim()))
            {
                od.Append = string.Format("StartTime >= '{0}' and StartTime <= '{1}'", txtTimeFrom.Text.Trim(), txtTimeTo.Text.Trim());
            }
            else if (string.IsNullOrEmpty(txtTimeFrom.Text.Trim()) && !string.IsNullOrEmpty(txtTimeTo.Text.Trim()))
            {
                od.Append += string.Format("StartTime <= '{0}'", txtTimeTo.Text.Trim());
            }
            od.SortFields = "AddTime desc";
            return od;
        }
        /// <summary>
        /// 翻页
        /// </summary> 
        protected void AspNetPager1_OnPageChanged(object sender, EventArgs e)
        {
            SetBind();
        }

        /// <summary>
        /// 执行查询
        /// </summary> 
        protected void btnButton_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
        } 
    }
}